// 
// Bachelor of Software Engineering
// Media Design School
// Auckland
// New Zealand
//
// (c) 2005 - 2014 Media Design School
//
// File Name	: GameApp.h
// Desrciption	: CGameApp declaration file.
// Author(s)	: Hayden Asplet.
// Mail			: hayden.asplet@mediadesignschool.com
//

#pragma once

#ifndef __GAMEAPP_H__
#define __GAMEAPP_H__

// Local Includes
#include "GameLogic.h"
#include "../Utilities/Point.h"
#include "Sprite/Sprite.h"
#include "Sprite/Renderer.h"

#define WINDOW_CLASS_NAME L"WINCLASS1"

class CGameApp {
	// Member Functions
public:
	CGameApp();
	virtual ~CGameApp();

	// These functions must be overidden by derived 
	// classes in order to instantiate them.
	virtual CGameLogic* VCreateGame() = 0;
	virtual HICON VGetIcon() = 0;
	virtual TCHAR* VGetTitle() = 0;

	virtual CPoint VGetScreenSize();
	virtual DWORD VGetWindowFlags();
	virtual LPTSTR VGetMenuName();

	// Win32 Specific Functions
	HWND GetHwnd() const;
	HINSTANCE GetInstance() const;

	virtual bool VInitialize(HINSTANCE _hInstance, 
							 LPSTR _lpCmdLine, 
							 HWND _hWnd = NULL,
							 int _iFrameRate = g_kiFRAMES_PER_SEC);

	static LRESULT CALLBACK MsgProc(HWND _hWnd, UINT _msg, WPARAM _wParam, LPARAM _lParam); // The message handler.
	
	virtual bool VOnCommand(WORD _command) = 0;

	// Game Application Functions
	void Update();
	void OnRender();
	LRESULT OnClose();		// Clean up.

	std::wstring LoadTextFromFile(const std::string& _krFileName);
	void RenderText(const std::wstring& _krText, const CPoint& _krPosition);

	CSprite LoadSprite(int _id);
	void RenderSprite(const CSprite& _sprite, int _iX, int _iY, int _iFrame = 0);

	CPoint GetScreenSize() const;
	bool IsRunning() const;

	CPoint GetMousePosition() const;
	bool IsDragging() const;
protected:
private:
	// Disallow copying.
	CGameApp(const CGameApp& _appOther);
	CGameApp& operator=(const CGameApp& _appOther);

	void UpdateScreenSize(const CPoint& _screenSize);

	// Member Variables
public:
	CGameLogic* m_pGame;		// The game logic.

protected:
	HWND m_hWnd;				// The handle to the window.
	HINSTANCE m_hInstance;		// The handle to the instance.

	CRenderer* m_pRenderer;		// The app's renderer;

	bool m_bIsRunning;			// True if the app is running, false otherwise.
	CPoint m_screenSize;		// The app's screen size.
	float m_fDeltaTime;			// The time of the last tick.
	int m_iFrameRate;			// The frame rate to lock the game tick at in frames per second.

	// Input specific variables
	CPoint m_mousePosition;		// The mouse position. (JG)
	CPoint m_dragStartingPoint; // The starting position of a drag.

	bool m_bIsDragging;
	bool m_bIsLMBDown;			// Is the lmb down (JG)
	bool m_bIsRMBDown;			// Is the rmb down (JG)
private:
};

extern CGameApp* g_pApp;

#endif